<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>计算年龄</title>
    <script>
        var age = prompt('请输入你的出生年份');
        var age1 = 2022 - parseInt(age);//也可以隐式转换
        alert('你的年龄是' + age1);
    </script>
</head>

<body>

</body>

</html>